﻿using Factory.MasterData.Materials.Dto;
using Factory.ProductionManagement.ProcedureSettings.Dto;
using Factory.QualityControl.CommonDefects;
using Factory.QualityControl.CommonDefects.Dto;
using IronSoftware.Enums;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Factory.Web.Controllers.QualityControl.CommonDefects
{
    public class CommonDefectController : Controller
    {
        /// <summary>
        /// 常见缺陷仓储接口
        /// </summary>
        private readonly ICommonDefectAppService _appService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="appService">常见缺陷仓储接口</param>
        public CommonDefectController(ICommonDefectAppService appService)
        {
            _appService = appService;
        }

        /// <summary>
        /// 打开视图
        /// </summary>
        /// <returns>转到视图</returns>
        public IActionResult CommonDefect()
        {
            return View();
        }
        /// <summary>
        /// 添加常见缺陷
        /// </summary>
        /// <param name="commonDefectDto">常见缺陷的数据</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Insert(CommonDefectDto commonDefectDto)
        {
            var reslut = await _appService.Insert(commonDefectDto);
            return reslut;
        }
        /// <summary>
        /// 常见缺陷信息分页显示
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="inquireInfo">常见缺陷描述</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<PageResult> PageList(int pageIndex, int pageSize, string? inquireInfo)
        {
            var reslut = await _appService.PageList(pageIndex, pageSize, inquireInfo);
            return reslut;
        }
        /// <summary>
        /// 删除常见缺陷信息
        /// </summary>
        /// <param name="id">常见缺陷主键</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Deleted(string id)
        {
            var reslut = await _appService.Deleted(id);
            return reslut;
        }
        /// <summary>
        /// 编辑常见缺陷信息
        /// </summary>
        /// <param name="commonDefectDto">编辑的常见缺陷</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Update(CommonDefectDto commonDefectDto)
        {
            var reslut = await _appService.Update(commonDefectDto);
            return reslut;
        }
    }
}
